﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BranchOfSansar.Sansar.Register;

namespace BranchOfSansar.Register.Authentication
{
    public partial class frmUser : Form
    {
        public frmUser()
        {
            InitializeComponent();
        }

        private void frmUser_Load(object sender, EventArgs e)
        {
            BindGrid();
        }

        private void BindGrid()
        {
            using (RegisterClient reg = new RegisterClient(Globals.Token))
            {
                gridUser.DataSource = reg.UserList();
            } 
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            frmRegUser frm = new frmRegUser();
            if (frm.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
            {
                BindGrid();
            }
        }

        private void btnEdit_Click(object sender, EventArgs e)
        {
            if (viewUser.SelectedRowsCount < 1)
            {
                Globals.Warr("Өгөгдөл сонгогдоогүй байна!");
                return;
            }
            User usr = (User)viewUser.GetRow(viewUser.GetSelectedRows()[0]);
            frmRegUser frm = new frmRegUser(usr);
            if (frm.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
            {
                BindGrid();
            }
        }

       
    }
}
